<%@page
	import="com.neiquan.backstage.platform_alliance_member.PlatformAllianceMemberService"%>
<%@page
	import="com.neiquan.backstage.pub.bsc.dao.po.PlatformAllianceMember"%>
<%@page import="java.util.List"%>
<%@page import="com.neiquan.backstage.common.CommonService"%>
<%@page import="com.neiquan.backstage.common.util.SpringContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>租金缴纳</title>
<link rel="stylesheet" href="css/base.css" />
<link rel="stylesheet" href="css/main.css" />

</head>
<body bgcolor="#f0f0f0">
	<section class="mt tc">
		<section id="noStation" class="common_bg mt">
			<section class="perfect pd">
				<p class="form-inpt-p">
					<label>当前暂无工位信息</label>
				</p>
			</section>
			<section class="addr_sub pd">
				<input type="button" class="btn rent_submmit"
					onClick="gotoApplyPage()" value="申请工位">
			</section>
		</section>
		<section id="rental">
			<p class="rent_top pd">
				目前已缴费截止月份
				<time id="endTime" class="rent_time"></time>
			</p>
			<p id="noArrearage" class="rent_top pd">
				已欠费<span id="numberMonth"></span>个月<span>金额</span>
				<time id="arrearage" class="rent_time"></time>
				元
			</p>
			<section class="rent_bottom pd">
				<label class="rent-label">缴费</label>
				<section class="relative rent-input-wrap">
					<input class="month_inpt" type="text" placeholder="请选择" />个月 （<span
						id="sumRental"></span>元/月）<br>
					<time class="rent_tips">
						费用缴纳至<span id="endTime1"></span>
					</time>
					<ul class="rent_date" style="position: absolute;">
						<li><span onClick="addmulMonth(1)">1</span> <span
							onClick="addmulMonth(5)">5</span> <span onClick="addmulMonth(9)">9</span>
						</li>
						<li><span onClick="addmulMonth(2)">2</span> <span
							onClick="addmulMonth(16)">6</span> <span
							onClick="addmulMonth(10)">10</span></li>
						<li><span onClick="addmulMonth(3)">3</span> <span
							onClick="addmulMonth(7)">7</span> <span onClick="addmulMonth(11)">11</span>
						</li>
						<li><span onClick="addmulMonth(4)">4</span> <span
							onClick="addmulMonth(8)">8</span> <span onClick="addmulMonth(12)">12</span>
						</li>
					</ul>
				</section>
			</section>
			<p>
				合计金额
				<time id="totalPrice" class="rent_num"></time>
				元
			</p>
			<section class="rent_btn relative">
				<input type="button" class="btn rent_submmit" value="立即缴费"
					onClick="onPay()"> <a href="mystation.jsp"
					class="look_station">查看工位</a> <a href="rentnonerecord.jsp"
					class="rent_record">历史缴费记录</a>
			</section>
		</section>
		<section id="newly">
			<p class="rent_top pd">说明：因您有新申请工位，您需要先缴纳新工位的租金，缴纳的结束时间与您的上一批工位租金缴纳结束时间一致</p>
			<label class="rent-label">缴费</label>
			<p>
				你需缴费
				<time id="needPayment" class="rent_num"></time>
				元
			</p>
			<time class="rent_tips">
				费用缴纳至<span id="endTime2"></span>
			</time>
			<section class="rent_btn relative">
				<input type="button" class="btn rent_submmit" value="提交申请">
				<a href="mystation.jsp" class="look_station">查看工位</a> <a
					href="rentnonerecord.jsp" class="rent_record">历史缴费记录</a>
			</section>
		</section>
	</section>
</body>
<script src="js/jquery.min.js"></script>
<script src="angular-1.5.0-rc.2/angular.js"></script>
<script src="js/main.js"></script>
<script src="js/responsive.js"></script>
<script type="text/javascript">
	var arrearage = 0;
	var sumRental = 0;
	var endTime = 0;
	var endTime1 = 0;
	var numberMonth = 0
	var totalPrice = 0
	$(function() {
		$("#noStation").hide();
		$("#rental").hide();
		$("#newly").hide();
	});

	function onPay() {
		alert(123);
 		$.post("api/myPayWinXin/myPay", function(data) {
			alert(123);
		});
	}
	function onBridgeReady() {

		//获取appId、timeStamp、nonceStr、package、signType、paySign
		var addrip = "";
		var userid = "openId";
		var appId;
		var timeStamp;
		var nonceStr;
		var signType;
		var packAge;
		var paySign;
		$.post('/weixin/cj/Cjaction!getParameter.action', {
			addrip : addrip,
			userid : userid
		}, function(data) {
			var brandWCPayParameter = data[0];
			appId = brandWCPayParameter.appId;
			timeStamp = brandWCPayParameter.timeStamp;
			nonceStr = brandWCPayParameter.nonceStr;
			signType = brandWCPayParameter.signType;
			packAge = brandWCPayParameter.packAge;
			paySign = brandWCPayParameter.paySign;
			alert(paySign);
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
				"appId" : appId, //公众号名称，由商户传入     
				"timeStamp" : timeStamp, //时间戳，自1970年以来的秒数     
				"nonceStr" : nonceStr, //随机串     
				"package" : packAge,
				"signType" : signType, //微信签名方式:     
				"paySign" : paySign
			//微信签名 
			}, function(res) {
				if (res.err_msg == "get_brand_wcpay_request:ok") {
					alert("支付成功");
				}
			});
		}, "json");
	}

	/* 	function onBridgeReady(){
	 alert(123);
	 WeixinJSBridge.invoke(
	 'getBrandWCPayRequest', {
	 "appId" : "${appid}",     //公众号名称，由商户传入     
	 "timeStamp":"${paytimestamp}",         //时间戳，自1970年以来的秒数     
	 "nonceStr" : "${paynonceStr}", //随机串     
	 "package" : "${paypackage}",     
	 "signType" : "${paysignType}",         //微信签名方式:     
	 "paySign" : "${paySign}" //微信签名 
	 },
	 function(res){
	 alert(res.err_msg);  // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返
	 }
	 ); 
	 }*/
	function pay() {
		if (typeof WeixinJSBridge == "undefined") {
			if (document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
						false);
			} else if (document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		} else {
			onBridgeReady();
		}
	}

	//
	//获取全部信息判断显示
	$(function() {
		var url = "api/paymentAction/allInfo";
		$.post(url, function(data) {
			var listL = data.response.listL;
			var listP = data.response.listP;
			if (listL.length <= 0) {
				$("#noStation").show();
			} else if (listP.length <= 0) {
				var myTime = 0;
				for (i = 0; i < listL.length; i++) {
					if (listL[i].newlyStuats == 0 && listL[i].status == 1) {
						sumRental = listL[i].sumRental;
						myTime = listL[i].stratTime;
						break;
					}
				}
				var time = new Date();
				time.setTime(myTime);
				var year = time.getFullYear();
				var month = time.getMonth() + "";
				var day = time.getDate() + "";
				if (month.length == 1) {
					month = "0" + month;
				}
				if (day.length == 1) {
					day = "0" + day;
				}
				endTime = year + "-" + month + "-" + day;
				$("#endTime").text(endTime);
				$("#sumRental").text(sumRental);
				$("#rental").show();
				$.post("api/paymentAction/firstPayment", function(data1) {
					arrearage = data1.response.arrearage;
					//endTime=data1.response.endTime;
					numberMonth = data1.response.numberMonth;
					$("#arrearage").text(arrearage);
					$("#numberMonth").text(numberMonth);
				});
			} else {
				var leaseId = 0;
				var falge1 = false;
				for (i = 0; i < listL.length; i++) {
					console.log(21);
					if (listL[i].newlyStuats == 1 && listL[i].status == 1) {
						leaseId = listL[i].leaseId;
						sumRental = listL[i].sumRental;
						myTime = listL[i].stratTime;
						falge1 = true;
						break;
					}
				}
				if (falge1) {
					$.post("api/paymentAction/findPayment", {
						"leaseId" : leaseId
					}, function(data2) {
						$("#newly").show();
						var needPayment = data2.response.needPayment;
						console.log(needPayment);
						var endTime1 = data2.response.endTime1;
						console.log(endTime1);
						var time = new Date();
						time.setTime(endTime1);
						var year = time.getFullYear();
						var month = time.getMonth() + "";
						var day = time.getDate() + "";
						if (month.length == 1) {
							month = "0" + month;
						}
						if (day.length == 1) {
							day = "0" + day;
						}
						var endTime2 = year + "-" + month + "-" + day;
						console.log(endTime2);
						$("#needPayment").text(needPayment);
						$("#endTime2").text(endTime2);
					});
				}
			}
		});
	});
	//年月日相加 和需要的总价格
	function addmulMonth(numMonth) {
		// n个月后
		var numMonth = parseInt(numMonth);
		var str = endTime;
		var time = new Date(Date.parse(str.replace(/-0/g, "-")));
		time.setMonth(time.getMonth() + (numMonth + 1))
		var time1 = new Date();
		time1.setTime(time);
		var year = time1.getFullYear();
		var month = time1.getMonth() + "";
		var day = time1.getDate() + "";
		if (month.length == 1) {
			month = "0" + month;
		}
		if (day.length == 1) {
			day = "0" + day;
		}
		endTime1 = year + "-" + month + "-" + day;
		//计算总花费
		sumRental = parseInt(sumRental);
		totalPrice = (sumRental * numMonth) + parseFloat(arrearage);
		$("#totalPrice").text(totalPrice);
		$("#endTime1").text(endTime1);
	}
</script>
</html>
